import { constantRoutes, asyncRoutes } from "../../router";
console.log(asyncRoutes, 6666);

export default {
  namespaced: true,
  state: {
    routes: constantRoutes // 所有人默认拥有静态路由
  },
  mutations: {
    setRoutes(state, newRoutes) {
      state.routes = [...constantRoutes, ...newRoutes];
    }
  },
  actions: {
    filterRoutes({ commit }, menus) {
      //  menus  获取用户信息中的路由菜单
      /* 
      constantRoutes    静态路由
      asyncRoutes   动态路由  
      menus循环  获取每一项跟动态路由中的是否有相同的并找到
       */
      var routes = [];
      menus.forEach(key => {
        //  找出menus中的每一项跟配置的动态路由相同的收集起来
        // console.log(key, 9999);
        routes.push(...asyncRoutes.filter(item => item.names == key));
      });
      commit("setRoutes", routes);
      return routes; // 这里为什么还要return  state数据 是用来 显示左侧菜单用的  return  是给路由addRoutes用的
    }
  }
};
